import axios from 'axios';

const API_URL = 'http://localhost:9000'; // 替换为你的后端地址
import { Annotation } from '../model/Annotation';

export class ReportReviewDetailService {
    // 获取批注
  static async getAnnotationByReportId(reportId: number) {
    try {
      const response = await axios.get(`${API_URL}/reportAnnotation/getReviewingReportByReportId`, {
        params: { reportId },
      });
      return response.data;
    } catch (error) {
      console.error('获取批注失败:', error);
      throw error;
    }
  }

  // 保存批注
  static async saveAnnotation(annotation:Annotation) {
    try {
      const response = await axios.post(`${API_URL}/reportAnnotation/saveOrUpdate`, annotation);
      console.log(response.data);
      return response.data;
    } catch (error) {
      console.error('保存批注失败:', error);
      throw error;
    }
  }

  // 提交审核结果
  static async submitReview(reportId: number, text: string, status: string) {
    try {
      console.log(reportId+"  "+text+"    "+status)
      const response = await axios.post(`${API_URL}/projectReport/submitReportReview`, {
        reportId,
        text,
        status,
      });
      console.log(response);
      return response.data;
    } catch (error) {
      console.error('提交审核结果失败:', error);
      throw error;
    }
  }

  // 根据报告Id获取其Url
  static async getReportUrlById(id: number) {
    try {
      console.log("查找报告的id:"+id);
      const response = await axios.get(`${API_URL}/projectReport/getReportUrlById`, {
        params: { id }  // 使用 `params` 传递查询参数
      });
      return response.data;
    } catch (error) {
      console.error('根据id获取报告失败:', error);
      throw error;
    }
  }

  // 获取报告列表
  static async getReports() {
    try {
      const response = await axios.get(`${API_URL}/projectReport/getAll`);
      return response.data;
    } catch (error) {
      console.error('获取报告列表失败:', error);
      throw error;
    }
  }
}